//
//  HRDynamicCell.m
//  Hear
//
//  Created by mac on 2017/3/26.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRDynamicCell.h"
#import "YYControl.h"
#import "HRDunamicLayout.h"
#import "YYPhotoGroupView.h"
#import "NSDate+Category.h"
#import "HRCoverTimeModel.h"
#import "NSMutableAttributedString+GDAttString.h"
#import "HRCoverImageModel.h"
#import "HRDynamicCommentModel.h"
#import "Track.h"
#import "DOUAudioStreamer.h"
#import "HRTopicInfoViewController.h"
#import "HRGetSoundQuestionsModel.h"
@implementation HRDynamicTimeView
-(void)setLayout:(HRDunamicLayout *)layout{
    self.timeImageView.frame = CGRectMake(10, 5, self.height-10, self.height-10);
    self.timeLabel.frame = CGRectMake(self.timeImageView.right+5, 0, self.width-self.timeImageView.right-5, self.height);
    self.timeLabel.text = [HRCoverTimeModel covetMyDynamicTime:layout.dynamicModel.CreateTime];
    DDLog(@"timeLabel==========================%@",self.timeLabel.text);
    DDLog(@"CreateTime==========================%@",layout.dynamicModel.CreateTime);
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        self.layer.cornerRadius = 3;
        self.backgroundColor = [UIColor whiteColor];
        
        self.timeImageView = [UIImageView new];
        self.timeImageView.image = [UIImage imageNamed:@"Calendar"];
        [self addSubview:self.timeImageView];
        
        self.timeLabel = [UILabel new];
        self.timeLabel.textColor = FirstTextColor;
        self.timeLabel.font = CustomUIFont(14);
        [self addSubview:self.timeLabel];
        
        
        
    }
    return self;
}
@end


@implementation HRDynamicContentBottomView
-(void)setLayout:(HRDunamicLayout *)layout{
    self.lineLabel.frame = CGRectMake(0, 0, self.width, 0.5);

    self.timeImageView.frame = CGRectMake(10, 8, self.height-16, self.height-16);

    self.timeLabel.frame = CGRectMake(self.timeImageView.right+5, 0, 140, self.height);
    
    self.timeLabel.text = [HRCoverTimeModel covetMyDynamicBottomTime:layout.dynamicModel.CreateTime];
    
    if (layout.dynamicModel.PositionName.length){
        NSArray *array = [layout.dynamicModel.PositionName componentsSeparatedByString:@","];
        if (array.count < 2)return;
        [self.addressButton setTitle:array[1] forState:0];
        NSDictionary *dic = @{NSFontAttributeName:CustomUIFont(13), NSParagraphStyleAttributeName:[NSMutableParagraphStyle new], NSKernAttributeName:@0.0f};
        CGFloat addressWidth = [self.addressButton.titleLabel.text boundingRectWithSize:CGSizeMake(self.width-self.timeLabel.right, self.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size.width+10;
        
        self.addressButton.frame = CGRectMake(self.width-addressWidth-5, 0, addressWidth, self.height);

    }
}

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self){
        
        UILabel *lineLabel = [UILabel new];
        lineLabel.backgroundColor = CustomColor(240, 240, 240, 1);
        [self  addSubview:(self.lineLabel=lineLabel)];
        
        UIImageView *timeImageView = [UIImageView new];
        timeImageView.image = [UIImage imageNamed:@"Clock"];
        [self addSubview:(self.timeImageView=timeImageView)];
        
        
        UILabel *timeLabel = [UILabel new];
        timeLabel.font = CustomUIFont(13);
        timeLabel.textColor = SecondTextColor;
        [self  addSubview:(self.timeLabel=timeLabel)];
        
        
        self.addressButton = [UIButton new];
        [self.addressButton setImage:[UIImage imageNamed:@"位置"] forState:0];
        self.addressButton.hidden = YES;
        [self.addressButton setTitleColor:SecondTextColor forState:0];
        self.addressButton.titleLabel.font = CustomUIFont(13);
        [self addSubview:self.addressButton];
        
        
    }
    return self;
}
@end



static void *kStatusKVOKey = &kStatusKVOKey;
static void *kDurationKVOKey = &kDurationKVOKey;
static void *kBufferingRatioKVOKey = &kBufferingRatioKVOKey;
@interface HRSoundButton ()
@property(nonatomic, strong)DOUAudioStreamer *streamer;

@end
@implementation HRSoundButton

-(void)setCommentModel:(HRDynamicCommentModel *)commentModel{
    _commentModel = commentModel;
    
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setImage:[UIImage imageNamed:@"语音播放长条"] forState:0];
        self.leftImageView.frame = CGRectMake(15, 10, 13, 18);
        self.voiceImageView.frame = CGRectMake(self.leftImageView.right+10, 12, 20, 15);
        self.voiceTimeLabel.frame = CGRectMake(self.voiceImageView.right, -5, self.width-self.voiceImageView.right-15, self.height);
    });
    
//    if (self.height){
//        self.voiceTimeLabel.frame = CGRectMake(self.voiceImageView.right, 0, self.width-self.voiceImageView.right-15, self.height);
//    }else{
//        self.voiceTimeLabel.frame = CGRectMake(60, 0, self.width-self.voiceImageView.right-15, 30);
//    }
    
    self.soundUrl = commentModel.SoundUrl;
    
    if (commentModel.isPlaying){
        [self.voiceImageView startAnimating];

    }else{
        [self.voiceImageView stopAnimating];
    }
    
    self.voiceTimeLabel.text = [NSString stringWithFormat:@"%@S ", commentModel.SoundLength];


}

-(void)setExampleModel:(HRSoundExampleModel *)exampleModel{
    _exampleModel = exampleModel;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setImage:[UIImage imageNamed:@"语音播放长条"] forState:0];
        self.leftImageView.frame = CGRectMake(15, 10, 13, 18);
        self.voiceImageView.frame = CGRectMake(self.leftImageView.right+10, 12, 20, 15);
        self.voiceTimeLabel.frame = CGRectMake(self.voiceImageView.right, -5, self.width-self.voiceImageView.right-15, self.height);
    });
    
    self.soundUrl = [exampleModel.SoundUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    if (exampleModel.isPlaying){
        [self.voiceImageView startAnimating];

    }else{
        [self.voiceImageView stopAnimating];
    }
    self.voiceTimeLabel.text = [NSString stringWithFormat:@"%@S ", exampleModel.SoundLength];



}
-(void)setDynamicModel:(HRDynamicModel *)dynamicModel{
    
    _dynamicModel = dynamicModel;
    
    if([dynamicModel.MomentType intValue] != 1 && [dynamicModel.MomentType intValue] != 5){
        self.voiceImageView.hidden = YES;
        self.voiceTimeLabel.hidden = YES;
        self.hidden = YES;
        self.voiceImageView.hidden = YES;

    }else{
        self.voiceImageView.hidden = NO;
        self.voiceTimeLabel.hidden = NO;
        self.hidden = NO;
        self.voiceImageView.hidden =NO;
    }
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setImage:[UIImage imageNamed:@"语音播放长条"] forState:0];
        self.leftImageView.frame = CGRectMake(15, 10, 13, 18);
        self.voiceImageView.frame = CGRectMake(self.leftImageView.right+10, 12, 20, 15);
        self.voiceTimeLabel.frame = CGRectMake(self.voiceImageView.right, -5, self.width-self.voiceImageView.right-15, self.height);
        
    });
    
    
    _dynamicModel = dynamicModel;
    if (dynamicModel.MomentLength){
        self.voiceTimeLabel.text = [NSString stringWithFormat:@"%@S ", dynamicModel.MomentLength];
    }
    
    self.soundUrl = _dynamicModel.MomentDetai;
    
    if (dynamicModel.isPlaying){
        [self.voiceImageView startAnimating];

    }else{
        [self.voiceImageView stopAnimating];
    }
    

    
}

-(void)setFunChatModel:(HRFunChatModel *)funChatModel{
    _funChatModel = funChatModel;
    
    self.voiceImageView.hidden = NO;
    self.voiceTimeLabel.hidden = NO;
    self.hidden = NO;
    self.voiceImageView.hidden =NO;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setImage:[UIImage imageNamed:@"语音播放长条"] forState:0];
        self.leftImageView.frame = CGRectMake(15, 10, 13, 18);
        self.voiceImageView.frame = CGRectMake(self.leftImageView.right+10, 12, 20, 15);
        self.voiceTimeLabel.frame = CGRectMake(self.voiceImageView.right, -5, self.width-self.voiceImageView.right-15, self.height);
        
    });
    
    
    if (funChatModel.SoundLength){
        self.voiceTimeLabel.text = [NSString stringWithFormat:@"%@S ", funChatModel.SoundLength];
    }
    
    self.soundUrl = funChatModel.SoundUrl;
    
    if (funChatModel.isPlaying){
        [self.voiceImageView startAnimating];
        
    }else{
        [self.voiceImageView stopAnimating];
    }
}


- (void)soundButtonClick{
    
    if (!self.soundUrl.length){
        [MBProgressHUD showMessage:@"当前音频文件为空" finishBlock:nil];
        return;
    }
    
    if (self.dynamicModel){
        [self dynamicClickSound];
    }else if (self.exampleModel){
        [self exampleClickSound];
    }else if (self.commentModel){
        [self commentClickSound];
    }else if(self.funChatModel){
        [self funChatClickSound];
    }else{
        [self enditUserSound];
    }
    DDLog(@"_soundUrl===========================%@",_soundUrl);
    
    
    
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if (context == kStatusKVOKey) {
        [self performSelector:@selector(updateStatus)
                     onThread:[NSThread mainThread]
                   withObject:nil
                waitUntilDone:NO];
    } else if (context == kDurationKVOKey) {
//        [self performSelector:@selector(updateSliderValue:)
//                     onThread:[NSThread mainThread]
//                   withObject:nil
//                waitUntilDone:NO];
    } else if (context == kBufferingRatioKVOKey) {
//        [self performSelector:@selector(updateBufferingStatus)
//                     onThread:[NSThread mainThread]
//                   withObject:nil
//                waitUntilDone:NO];
    } else {
        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
    }
}


- (void)updateStatus {
    //    self.musicIsPlaying = NO;
//        _musicIndicator.state = NAKPlaybackIndicatorViewStateStopped;

    switch ([_streamer status]) {
        case DOUAudioStreamerPlaying:
            DDLog(@"=====================DOUAudioStreamerPlaying");
            break;
            
        case DOUAudioStreamerPaused:
            DDLog(@"=====================DOUAudioStreamerPaused");
            break;
            
        case DOUAudioStreamerIdle:
            DDLog(@"=====================DOUAudioStreamerIdle");
            break;
            
        case DOUAudioStreamerFinished:
            DDLog(@"=====================DOUAudioStreamerFinished");
           [self.voiceImageView stopAnimating];
            break;
            
        case DOUAudioStreamerBuffering:
            DDLog(@"=====================DOUAudioStreamerBuffering");
            break;
            
        case DOUAudioStreamerError:
            DDLog(@"=====================DOUAudioStreamerError");
            break;
    }
}




- (void)createPlayer{
   

    Track *track = [[Track alloc] init];
    track.audioFileURL = [NSURL URLWithString:self.soundUrl];
    [self removeStreamerObserver];

    @try {
        [self removeStreamerObserver];
    } @catch(id anException){
    }
    
    
    _streamer = nil;
    _streamer = [DOUAudioStreamer streamerWithAudioFile:track];
    
    [self addStreamerObserver];
    [self.streamer play];
    
    DDLog(@"=====================创建了DOUAudioStreamer");
    
}

- (void)removeStreamerObserver {
    [_streamer removeObserver:self forKeyPath:@"status"];
    [_streamer removeObserver:self forKeyPath:@"duration"];
    [_streamer removeObserver:self forKeyPath:@"bufferingRatio"];
}

- (void)addStreamerObserver {
    [_streamer addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:kStatusKVOKey];
    [_streamer addObserver:self forKeyPath:@"duration" options:NSKeyValueObservingOptionNew context:kDurationKVOKey];
    [_streamer addObserver:self forKeyPath:@"bufferingRatio" options:NSKeyValueObservingOptionNew context:kBufferingRatioKVOKey];
}



- (void)commentClickSound{
    if (self.commentModel.isPlaying){
        self.commentModel.isPlaying = NO;
        [self.streamer pause];

        if (self.playCommentMedioBlock){
            self.playCommentMedioBlock(self.commentModel);
        }

    }else{
        self.commentModel.isPlaying = YES;
        [self createPlayer];

        if (self.playCommentMedioBlock){
            self.playCommentMedioBlock(self.commentModel);
        }
    }
}

- (void)funChatClickSound{
    if (self.funChatModel.isPlaying){
        self.funChatModel.isPlaying = NO;
        [self.streamer pause];
        
        if (self.playFunChatMedioBlock){
            self.playFunChatMedioBlock(self.funChatModel);
        }
        
    }else{
        self.funChatModel.isPlaying = YES;
        [self createPlayer];
        
        if (self.playFunChatMedioBlock){
            self.playFunChatMedioBlock(self.funChatModel);
        }
    }
}


- (void)enditUserSound{
    if (self.isPlaying){
        self.isPlaying = NO;
        [self.voiceImageView stopAnimating];
        [self.streamer pause];


    }else{
        self.isPlaying = YES;
        [self.voiceImageView startAnimating];
        [self createPlayer];


    }
}


- (void)exampleClickSound{
    if (self.exampleModel.isPlaying){
        self.exampleModel.isPlaying = NO;
        [self.streamer pause];
        if (self.playExampleMedioBlock){
            self.playExampleMedioBlock(self.exampleModel);
        }
        
        
    }else{
        self.exampleModel.isPlaying = YES;
        [self createPlayer];
        
        if (self.playExampleMedioBlock){
            self.playExampleMedioBlock(self.exampleModel);
        }
    }
}


- (void)dynamicClickSound{
    if (self.dynamicModel.isPlaying){
        self.dynamicModel.isPlaying = NO;
        if (self.playMedioBlock){
            self.playMedioBlock(self.dynamicModel);
        }
        [self.streamer pause];
        
    }else{
        self.dynamicModel.isPlaying = YES;
        [self createPlayer];
        
        if (self.playMedioBlock){
            self.playMedioBlock(self.dynamicModel);
        }
    }
}

- (void)stopPlayVoiceNotification{
    [self removeStreamerObserver];
    [self.streamer pause];
    self.streamer = nil;
}


-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self addTarget:self action:@selector(soundButtonClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        self.leftImageView = [UIImageView new];
        self.leftImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.leftImageView.clipsToBounds = YES;
        [self addSubview:self.leftImageView];
        self.leftImageView.image = [UIImage imageNamed:@"语音图标"];
        
        
        self.voiceImageView = [UIImageView new];
        self.voiceImageView.contentMode = UIViewContentModeScaleAspectFill;
        self.voiceImageView.clipsToBounds = YES;
        [self addSubview:self.voiceImageView];
        self.voiceImageView.image = [UIImage imageNamed:@"语音气泡5"];
        
        NSArray * animateNames = @[@"语音气泡1",@"语音气泡2",@"语音气泡3",@"语音气泡4",@"语音气泡5"];
        
        NSMutableArray * animationImages = [[NSMutableArray alloc] initWithCapacity:animateNames.count];
        for (NSString * animateName in animateNames) {
            UIImage * animateImage = [UIImage imageNamed:animateName];
            [animationImages addObject:animateImage];
        }
        self.voiceImageView.animationImages = animationImages;
        self.voiceImageView.animationDuration = 1.0;
        
        self.voiceImageView.userInteractionEnabled = NO;
        
        
        self.voiceTimeLabel = [UILabel new];
        self.voiceTimeLabel.textAlignment = NSTextAlignmentRight;
        self.voiceTimeLabel.textColor = [UIColor whiteColor];
        self.voiceTimeLabel.font = CustomUIFont(14);
        [self addSubview:self.voiceTimeLabel];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopPlayVoiceNotification) name:@"stopPlayVoiceNotification" object:nil];
    }
    return self;
}


@end

@implementation VBContentView
-(void)setLayout:(HRDunamicLayout *)layout{
    _layout = layout;
    
    
    WeakSelf
    self.contentLabel.frame = layout.contentRect;
    
    self.soundButton.frame = layout.soundButtonRect;
    
    self.soundAndImageView.frame = layout.soundAndImageViewFrame;
    
    self.photoView.frame = layout.dynamicPhotoViewFrame;
    
    self.bottomView.frame = layout.bottomViewRect;
    
    self.lockImageView.frame = layout.lockImageViewRect;

    [HRCoverImageModel OriginImage:[UIImage imageNamed:@"锁-"] scaleToSize:self.lockImageView.size callBackOriginImage:^(UIImage *originImage) {
        weakSelf.lockImageView.image = originImage;
    }];
    

    
    
    self.contentLabel.attributedText = [NSMutableAttributedString attStringFromTextForChatting:layout.dynamicModel.MomentNotes textFont:CustomUIFont(14)];
    
    
    
    

    
    self.bottomView.layout = layout;

    
    if (!layout.dynamicModel.Permission && ![layout.dynamicModel.UserLocalId isEqualToString:USERID]){
        self.contentLabel.text = @"该动态上锁了，你想要钥匙吗";
        self.soundButton.hidden = YES;
        self.photoView.hidden = YES;
        self.soundAndImageView.hidden = YES;
        return;
    }else if (!layout.dynamicModel.Permission){
        self.bottomView.timeLabel.text = [NSString stringWithFormat:@"%@ 仅自己可见",self.bottomView.timeLabel.text];
    }

    
    
    if ([layout.dynamicModel.MomentType intValue] == 1){
        self.photoView.hidden = YES;
        self.soundAndImageView.hidden = YES;
        self.soundButton.hidden = NO;
        self.soundButton.dynamicModel = layout.dynamicModel;
    }else if ([layout.dynamicModel.MomentType intValue] == 2 ||[layout.dynamicModel.MomentType intValue] == 3){
        self.photoView.hidden = NO;
        if(layout.dynamicModel.pics){
            self.photoView.picArr = layout.dynamicModel.pics;
        }else{
            self.photoView.hidden = YES;
        }
        self.soundAndImageView.hidden = YES;
        self.soundButton.hidden = YES;
    }else if ([layout.dynamicModel.MomentType intValue] == 5){
        self.photoView.hidden = YES;
        self.soundAndImageView.hidden = NO;
        self.soundButton.hidden = YES;
        layout.dynamicModel.MomentLength = layout.dynamicModel.soundAndImageConentModel.SoundLength;
        layout.dynamicModel.MomentDetai = layout.dynamicModel.soundAndImageConentModel.SoundUrl;
        self.soundAndImageView.dynamicModel = layout.dynamicModel;
    }

    if (!weakSelf.layout.dynamicModel.QuestionText.length){
        self.contentLabel.userInteractionEnabled = NO;
    }else{
        self.contentLabel.userInteractionEnabled = YES;
    }
    

    
}



-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        WeakSelf
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 5;
        
        _lockImageView = [UIImageView new];
        [self addSubview:_lockImageView];
        
        
        _contentLabel = [YYLabel new];
        _contentLabel.numberOfLines = 0;
        _contentLabel.textColor = [UIColor blackColor];
        [self addSubview:_contentLabel];
        _contentLabel.font = CustomUIFont(14);
        UITapGestureRecognizer *contentTap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            if (!weakSelf.layout.dynamicModel.QuestionText.length)return ;
            HRGetSoundQuestionsModel *questionModel = [HRGetSoundQuestionsModel new];
            questionModel.ParentQuestionID = weakSelf.layout.dynamicModel.ParentQuestionID;
            questionModel.ParentQuestionText = weakSelf.layout.dynamicModel.ParentQuestionText;
            questionModel.QuestionID = weakSelf.layout.dynamicModel.QuestionID;
            questionModel.QuestionText = weakSelf.layout.dynamicModel.QuestionText;
            HRTopicInfoViewController *VC = [HRTopicInfoViewController new];
            VC.model = questionModel;
            [VIEWCCONTROLER.navigationController pushViewController:VC animated:YES];
        }];
        [self.contentLabel addGestureRecognizer:contentTap];

        _soundButton = [HRSoundButton buttonWithType:0];
        [self addSubview:_soundButton];
        
        
        _soundButton.playMedioBlock = ^(HRDynamicModel *currentDynamicModel){
            if (weakSelf.playMedioBlock){
                weakSelf.playMedioBlock(currentDynamicModel);
            }
        };
        
        _soundAndImageView = [HRDynamicSoundAndImageBackGroundView new];
        [self addSubview:_soundAndImageView];
        self.soundAndImageView.playMedioBlock = ^(HRDynamicModel *currentDynamicModel){
            if (weakSelf.playMedioBlock){
                weakSelf.playMedioBlock(currentDynamicModel);
            }
        };
        
        
        self.photoView = [HRFollowDynamicPhotoView new];
        [self addSubview:self.photoView];
        
        
        self.bottomView = [HRDynamicContentBottomView new];
        [self addSubview:self.bottomView];
    
    }
    return self;
}

@end






@implementation HRDynamicCell


-(void)setLayout:(HRDunamicLayout *)layout{
    _layout = layout;
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        self.timeView.frame = layout.timeViewRect;
        self.timeView.layer.shadowColor = [UIColor blackColor].CGColor;
        self.timeView.layer.shadowRadius      = 3;
        self.timeView.layer.shadowOpacity     = 0.2;
        self.timeView.layer.shadowOffset      = CGSizeMake(1, 1);
        self.timeView.layer.shadowPath        = [UIBezierPath bezierPathWithRect:self.timeView.bounds].CGPath;
        self.timeView.layout = layout;
        
        self.contenView.frame = layout.contentViewRect;
        self.contenView.layout = layout;
        
        self.contenView.layer.shadowColor = [UIColor blackColor].CGColor;
        self.contenView.layer.shadowRadius      = 3;
        self.contenView.layer.shadowOpacity     = 0.2;
        self.contenView.layer.shadowOffset      = CGSizeMake(1, 1);
        self.contenView.layer.shadowPath        = [UIBezierPath bezierPathWithRect:self.contenView.bounds].CGPath;
        if (self.layout.dynamicModel.isFromHistoryAnswer){
            self.deleteButton.frame = CGRectMake(self.contenView.width-60, self.contenView.height-60, 40, 20);
            self.deleteButton.hidden = NO;
        }else{
            self.deleteButton.hidden = YES;
        }
        
    });
    
    
    
}

- (void)deleteHistoryAnswerClick{
    if (self.deleteHistoryAnswerBlock){
        self.deleteHistoryAnswerBlock();
    }
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *cellID = @"HRDynamicCell";
    
    HRDynamicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        cell = [[HRDynamicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    if (self)
    {
        WeakSelf
        self.backgroundColor = [UIColor whiteColor];
        
        HRDynamicTimeView *timeView = [HRDynamicTimeView new];
        [self.contentView addSubview:(self.timeView=timeView)];
        
        
        
        _contenView = [VBContentView new];
        [self.contentView addSubview:self.contenView];
        _contenView.playMedioBlock = ^(HRDynamicModel *currentDynamicModel){
            if (weakSelf.playMedioBlock){
                weakSelf.playMedioBlock(currentDynamicModel);
            }
        };
        
        UIButton *deleteButton = [UIButton buttonWithType:0];
        [deleteButton setTitle:@"删除" forState:0];
        [deleteButton setTitleColor:FirstTextColor forState:0];
        deleteButton.titleLabel.font = CustomUIFont(13);
        [self.contenView addSubview:(self.deleteButton=deleteButton)];
        [deleteButton addTarget:self action:@selector(deleteHistoryAnswerClick) forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    return self;
}
@end


